<template>
  <el-dialog
    :title="title"
    :close-on-click-modal="false"
     v-dialogDrag
    :visible.sync="visible">
    <el-form size="small" :model="inputForm" ref="inputForm" :class="method==='view'?'readonly':''"  :disabled="method==='view'" @keyup.enter.native="doSubmit()"
             label-width="120px">
      <el-row  :gutter="15">
        <el-col :span="12">
            <el-form-item label="流程主表" prop="processMain.id"
                :rules="[
                 ]">
              <el-input v-model="inputForm.processMain.id" placeholder="请填写流程主表"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="流程" prop="processName.id"
                :rules="[
                 ]">
          <GridSelect
            title="选择流程"
            labelName = 'processName'
            labelValue = 'id'
            :value = "inputForm.processName.id"
            :limit="1"
            @getValue='(value) => {inputForm.processName.id=value}'
            :columns="[
            {
              prop: 'id',
              label: '主键'
            },
            {
              prop: 'processName',
              label: '流程名称'
            }
            ]"
            :searchs="[
            {
              prop: 'id',
              label: '主键'
            },
            {
              prop: 'processName',
              label: '流程名称'
            }
            ]"
            dataListUrl="/dlyrl/hr/processmain/processMain/list"
            entityBeanName="processMain"
            queryEntityUrl="/dlyrl/hr/processmain/processMain/queryById">
          </GridSelect>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="序号" prop="number"
                :rules="[
                 ]">
              <el-input v-model="inputForm.number" placeholder="请填写序号"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="审批角色" prop="attachRole.id"
                :rules="[
                 ]">
          <GridSelect
            title="选择审批角色"
            labelName = 'roleName'
            labelValue = 'id'
            :value = "inputForm.attachRole.id"
            :limit="1"
            @getValue='(value) => {inputForm.attachRole.id=value}'
            :columns="[
            {
              prop: 'id',
              label: '主键'
            },
            {
              prop: 'roleName',
              label: '角色名'
            }
            ]"
            :searchs="[
            {
              prop: 'id',
              label: '主键'
            },
            {
              prop: 'roleName',
              label: '角色名'
            }
            ]"
            dataListUrl="/dlyrl/hr/enterpriserole/enterpriseRoleInformation/list"
            entityBeanName="enterpriseRoleInformation"
            queryEntityUrl="/dlyrl/hr/enterpriserole/enterpriseRoleInformation/queryById">
          </GridSelect>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="审批类型" prop="attachType"
                :rules="[
                 ]">
                <el-select v-model="inputForm.attachType" placeholder="请选择"  style="width: 100%;">
                          <el-option
                            v-for="item in $dictUtils.getDictList('attachtype')"
                            :key="item.value"
                            :label="item.label"
                            :value="item.value">
                          </el-option>
                      </el-select>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="并行序号" prop="parallelNumber"
                :rules="[
                 ]">
              <el-input v-model="inputForm.parallelNumber" placeholder="请填写并行序号"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="失败返回序号" prop="failNumber"
                :rules="[
                 ]">
              <el-input v-model="inputForm.failNumber" placeholder="请填写失败返回序号"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="备注信息" prop="remarks"
                :rules="[
                  {required: true, message:'备注信息不能为空', trigger:'blur'}
                 ]">
          <el-input type="textarea" v-model="inputForm.remarks" placeholder="请填写备注信息"     ></el-input>
           </el-form-item>
        </el-col>
        </el-row>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button size="small" v-if="method === 'add'" type="primary" @click="continueDoSubmit()">继续添加</el-button>
      <el-button size="small" @click="visible = false">关闭</el-button>
      <el-button size="small" v-if="method !== 'view'" type="primary" @click="doSubmit()">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
  import GridSelect from '@/components/gridSelect'
  export default {
    data () {
      return {
        title: '',
        method: '',
        visible: false,
        oldInputForm: '',
        inputForm: {
          id: '',
          processMain: {
            id: ''
          },
          processName: {
            id: ''
          },
          number: '',
          attachRole: {
            id: ''
          },
          attachType: '',
          parallelNumber: '',
          failNumber: '',
          remarks: ''
        }
      }
    },
    components: {
      GridSelect
    },
    methods: {
      init (method, obj) {
        this.method = method
        if (method === 'add') {
          this.title = `新建流程附表`
        } else if (method === 'edit') {
          this.title = '修改流程附表'
        } else if (method === 'view') {
          this.title = '查看流程附表'
        }
        this.visible = true
        this.$nextTick(() => {
          this.$refs.inputForm.resetFields()
          this.inputForm.id = ''
          this.oldInputForm = ''
          if (method === 'edit' || method === 'view') { // 修改或者查看
            this.oldInputForm = obj
            this.inputForm = JSON.parse(JSON.stringify(obj))
          }
        })
      },
   // 表单提交
      doSubmit () {
        this.$refs['inputForm'].validate((valid) => {
          if (valid) {
            this.$emit('addRow', this.oldInputForm, JSON.parse(JSON.stringify(this.inputForm)))
            this.visible = false
          }
        })
      },
      continueDoSubmit () {
        this.$refs['inputForm'].validate((valid) => {
          if (valid) {
            this.$emit('addRow', this.oldInputForm, JSON.parse(JSON.stringify(this.inputForm)))
            this.$refs['inputForm'].resetFields()
          }
        })
      }
    }
  }
</script>